/**
 * 首尾都可插入和删除的队列为双端队列
 */
#include <iostream>
#include <deque>

using namespace std;

deque<int> init_deque();

void print_deque(deque<int> int_deque);

int main()
{
    // 初始化双端队列
    deque<int> int_deque = init_deque();
    print_deque(int_deque);
    // 返回队首元素 O(1)
    cout << int_deque.front() << endl;
    // 返回队尾元素 O(1)
    cout << int_deque.back() << endl;
    // 返回双端队列中元素个数，返回值类型unsigned int O(1)
    cout << int_deque.size() << endl;
    // 判断是否为空，双端队列为空，返回true O(1)
    if (int_deque.empty())
    {
        cout << "双端队列为空" << endl;
    } else
    {
        cout << "双端队列不为空" << endl;
    }
    return 0;
}

/**
 * 初始化双端队列
 * @return
 */
deque<int> init_deque()
{
    deque<int> int_deque;
    for (int i = 0; i < 5; i++)
    {
        int_deque.push_back(i);
    }
    return int_deque;
}

/**
 * 打印双端队列
 * @param int_deque
 */
void print_deque(deque<int> int_deque)
{
    while (!int_deque.empty())
    {
        cout << int_deque.front() << " ";
    }
    cout << endl;
}
